package cn.com.sd.system.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.com.sd.common.util.MyStringUtils;
import cn.com.sd.common.util.Page;
import cn.com.sd.system.dao.IOperatorDAO;
import cn.com.sd.system.model.Operator;

@SuppressWarnings("unchecked")
@Component(value = "operatorDAO")
public class OperatorDAOHibernate extends BaseDAOHibernate<Operator> implements IOperatorDAO{

	public List<Operator> getOperatorList(Page page) {
		return createQuery("from Operator").setFirstResult(page.getStartRow()).setMaxResults(page.getStartRow() + page.getPageSize()).list();
	}

	@Override
	public Operator validateLogin(Operator operator) {
		
		String hql = "from Operator oper left join fetch oper.roles left join fetch oper.privileges where oper.name=? and oper.password=? ";
		return (Operator) findUnique(hql,new String[]{operator.getName(), operator.getPassword()});
	}

	@Override
	public Integer getOperatorCount() {
		String hql = "select count(operator.id) from Operator operator";
		Long count = (Long) findUnique(hql);
		return MyStringUtils.translateLongToInteger(count);
	}
}
